#####
# Replication for: "Can Political Speech Foster Tolerance of Immigrants?" by Schleiter, Tavits, and Ward.
# Table S.6
#####

library(here)
library(data.table)
library(texreg)

# source the custom functions
source("functions.R")

# load the pooled data if not already in workspace
if(!exists("pooled")){
  pooled <- fread(here("data", "pooled.csv"))
}

# Fitting -----------------------------------------------------------------

s6_1 <- noCov(mechanism_NM, sample = "Pooled", chatty = F)
s6_2 <- allCov(mechanism_NM, sample = "Pooled", chatty = F)

s6_3 <- noCov(mechanism_CS, sample = "Pooled", chatty = F)
s6_4 <- allCov(mechanism_CS, sample = "Pooled", chatty = F)

s6_5 <- noCov(mechanism_CH, sample = "Pooled", chatty = F)
s6_6 <- allCov(mechanism_CH, sample = "Pooled", chatty = F)

# Reporting ---------------------------------------------------------------

# in the document, these three outputs are merged to a single latex table.

texregPS(
  list(s6_1, s6_2),
  custom.model.names = paste0("(", 1:2, ")"),
  custom.gof.rows = list(
    "All Covariates" = c("", "$\\checkmark$")
  )
)

texregPS(
  list(s6_3, s6_4),
  custom.model.names = paste0("(", 3:4, ")"),
  custom.gof.rows = list(
    "All Covariates" = c("", "$\\checkmark$")
  )
)

texregPS(
  list(s6_5, s6_6),
  custom.model.names = paste0("(", 5:6, ")"),
  custom.gof.rows = list(
    "All Covariates" = c("", "$\\checkmark$")
  )
)
